<?php
namespace app\daifast\controller;
use \think\Db;
use think\Session;


class Expert extends \think\Controller
{ 
    
    
    
    /**
     * 专家列表
     */
    public function index(){
         
        $names = addslashes(input('names')); 
        //查询条件
        $where = " 1=1 ";
        $names and $where .=" and names = '".$names."'"; 
       
        $pageQueryArr =["query"=>["names"=>$names]];
        $data = Db('baode_expert')->where($where)->order("id desc")->paginate(5,$pageQueryArr); 
        $listArr = $data->items();
        $pages = $data->render(); 
        
        return $this->allFetch(get_defined_vars());
    }
     
    /**
     * 删除
     */
    public function delete(){
        $id = intval(input('id'));
        
        Db('baode_expert')->where(['id'=>$id])->delete();
        
        $this->showMsg('删除成功', url('Expert/index'));
        
    }
    
    
    /**
     * 添加专家
     * @return mixed
     */
    public function add(){
      $eid = intval(input('eid'));
      $eid and $expertInfo = Db('baode_expert')->where(['id'=>$eid])->find();
        if(input('sbt')){ 
            $data['field'] = input('field');
            $data['names'] = input('names');
            $data['position'] = input('position');
            $data['photo'] = input('photo');
            $data['contents'] = htmlspecialchars(input('contents'));
            $data['brief_contents'] = htmlspecialchars(input('brief_contents'));
            $data['on_time'] = time(); 
            $eid and Db('baode_expert')->where(['id'=>$eid])->update($data); 
            $eid or Db('baode_expert')->insert($data); 
            $this->showMsg('操作成功', url('Expert/index'));
        }
        
        return $this->allFetch(get_defined_vars());
    }
    
    
    
    
    
    
    
    
}
